import {
  IsDate,
  IsEnum,
  IsNotEmpty,
  IsNumber,
  IsOptional,
  IsString,
} from 'class-validator';

export enum ArticleState {
  DRAFT = '草稿',
  PUBLISHED = '已发布',
}

export class ArticleDto {
  @IsNumber()
  @IsOptional()
  id: number;

  @IsString()
  @IsNotEmpty()
  title: string;

  @IsString()
  @IsNotEmpty()
  content: string;

  @IsString()
  @IsNotEmpty()
  cover_img: string;

  @IsEnum(ArticleState)
  @IsNotEmpty()
  state: string;

  @IsNumber()
  @IsNotEmpty()
  category_id: number;

  @IsNumber()
  @IsOptional()
  create_user?: number;

  @IsDate()
  @IsOptional()
  created_time?: Date;

  @IsDate()
  @IsOptional()
  update_time?: Date;
}

export class ArticleUpdateDto {
  @IsNumber()
  id: number;

  @IsString()
  @IsOptional()
  title: string;

  @IsString()
  @IsOptional()
  content: string;

  @IsString()
  @IsOptional()
  cover_img: string;

  @IsEnum(ArticleState)
  @IsOptional()
  state: string;

  @IsNumber()
  @IsOptional()
  category_id: number;

  @IsNumber()
  @IsOptional()
  create_user?: number;

  @IsDate()
  @IsOptional()
  created_time?: Date;

  @IsDate()
  @IsOptional()
  update_time?: Date;
}
